package com.wing.productself.model.entity;

import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.wing.mybatis.common.BaseEntity;
import com.wing.product.model.entity.ProductCategory;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

/**
 * 产品分类
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("pro_product_category")
public class ProductCategorySelf extends BaseEntity<ProductCategorySelf> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Type implements IEnum<Integer> {

        /**
        * 刀具
        */
        knife(0,"刀具"),
        /**
        * 柜子
        */
        cabnet(1,"柜子");

        private int code;
        private String desc;

        Type(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum DataSourceType implements IEnum<Integer> {

        /**
        * 企业
        */
        enterprise(0,"企业"),
        /**
        * 平台
        */
        platform(1,"平台");

        private int code;
        private String desc;

        DataSourceType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 父ID
     */
    private Long parentId;

    /**
     * 名称
     */
    private String name;

    /**
     * 是否终极分类
     */
    private Boolean isFinal;

    /**
     * 排序
     */
    private Integer sortNumber;

    /**
     * hasChild
     */
    private Boolean hasChild;

    /**
     * hasEnableChild
     */
    private Boolean hasEnableChild;

    /**
     * created:已创建,-1:已作废
     */
    private Integer status;

    /**
     * 类型
     */
    private Type type;

    /**
    * 类型描述
    */
    @TableField(exist = false)
    private String typeDesc;

    public String getTypeDesc() {
        return type == null ? null : type.getDesc();
    }

    /**
     * 数据来源
     */
    private DataSourceType dataSourceType;

    /**
    * 数据来源描述
    */
    @TableField(exist = false)
    private String dataSourceTypeDesc;

    public String getDataSourceTypeDesc() {
        return dataSourceType == null ? null : dataSourceType.getDesc();
    }

    /**
     * 平台端表id
     */
    private Long idPlatform;

    private ProductCategorySelf.CategoryType categoryType;
    //分类类型0:采购物资，1生产产品，2销售物资，3资产，4其他
    public enum CategoryType implements IEnum<Integer> {

        /**
         * 采购
         */
        purchase(0,"采购"),
        /**
         * 生产
         */
        production(1,"生产"),
        /**
         * 销售
         */
        sell(2,"销售"),
        /**
         * 资产
         */
        asset(3,"资产"),
        /**
         * 其他
         */
        other(4,"其他");


        private int code;
        private String desc;

        CategoryType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static ProductCategorySelf.CategoryType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (ProductCategorySelf.CategoryType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

}
